<template>
	<text>{{text}}</text>
</template>

<script>
	import {
		getDicData
	} from '@/api/common.js'
	import {
		validateNumberString
	} from "@/util/regulars.js"
	export default {
		props: {
			type: String,
			value: '',
		},
		data() {
			return {
				dicData: [],
				text: '',
			}
		},
		watch: {
			value(n, o) {
				this.setText();
			},
		},
		created() {
			this.init();
		},
		methods: {
			init() {
				getDicData(this.type).then(res => {
					this.dicData = res.data[this.type];
					this.setText();
				});
			},
			setText() {
				// version：1.1.2兼容处理，个人资料-增加自定义标签
				// 这里直接返回自定义标签，版本高于1.1.2之后，此段代码可以删掉
				if (this.type == "tag" && !validateNumberString.test(this.value)) {
					this.text = this.value;
					return
				}
				this.dicData.forEach((item, i) => {
					if (item.value == this.value) {
						this.text = item.name;
					}
				})
			},
		}
	}
</script>

<style>
</style>